/*
 * FilePath     : \src\utils\setting.ts
 * Author       : SJZ
 * Date         : 2025-03-12 19:28
 * LastEditors  : SJZ
 * LastEditTime : 2025-03-13 22:21
 * Description  : 读取系统配置文件
 * CodeIterationRecord:
 */

import common from "@/utils/common";
import http from "@/utils/http";
import axios from "axios";
// 先置空baseURL，读取本地配置文件
axios.defaults.baseURL = "";
let appConfig: any;

/**
 * @description: 初始化配置
 */
const initSetting = async () => {
  await axios.get("/static/config.json").then((res) => {
    appConfig = res.data;
    common.storage("mockMode", appConfig.mockMode);
    common.session("serverUrl", appConfig.serverUrl);
    if (appConfig.mockMode) {
      setMockApiUrl();
      return;
    }
    setServerApiUrl();
  });
};
/**
 * @description: 设置API服务地址
 */
const setServerApiUrl = () => {
  let serverUrl = `${common.session("serverUrl")}/api`;
  http.setApiUrl(serverUrl);
};
/**
 * @description: 设置测试API服务地址
 */
const setMockApiUrl = () => http.setApiUrl("/api");

export { initSetting, setServerApiUrl, setMockApiUrl };
